package com.ruoyi.server.api.favorites.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.server.api.favorites.domain.Favorites;
import com.ruoyi.server.api.favorites.service.FavoritesService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.*;

/**
 * @ClassName FavoritesController
 * @Description 点赞收藏操作Controller
 * @Author zsc
 * @Date 2024/10/16 14:43
 */
@RestController
@RequestMapping("/favorites/favorites")
public class FavoritesController {
    @Autowired
    private FavoritesService favoritesService;

    /**
    * @Author zsc
    * @Description 点赞图片id存储 或 移除
    * @Date 2024/10/16 19:41
    * @Return void
    * @param favorites
    */
    @PostMapping("/toggleLike")
    public AjaxResult saveOrDelUserImageLike(@RequestBody Favorites favorites) {
        return AjaxResult.success(favoritesService.saveOrDelUserImageLike(favorites));
    }


    /**
    * @Author zsc
    * @Description 获取用户点赞图片
    * @Date 2024/10/16 19:49
    * @Return com.ruoyi.server.api.favorites.domain.Favorites
    * @param userId
    */
    @GetMapping("/getUserImageLike")
    public AjaxResult getUserImageLike(@RequestParam("id") BigInteger userId) {
        return AjaxResult.success( favoritesService.getUserImageLikeById(userId));
    }

    /**
    * @Author zsc
    * @Description 收藏图片id存储 或 移除
    * @Date 2024/10/17 10:32
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param favorites
    */
    @PostMapping("/toggleCollection")
    public AjaxResult saveUserImageCol(@RequestBody Favorites favorites) {
        return AjaxResult.success(favoritesService.saveOrDelUserImageCol(favorites));
    }

    /**
     * @Author zsc
     * @Description 获取用户收藏图片
     * @Date 2024/10/16 19:49
     * @Return com.ruoyi.server.api.favorites.domain.Favorites
     * @param userId
     */
    @GetMapping("/getUserImageCollection")
    public AjaxResult getUserImageCol(@RequestParam("id")BigInteger userId) {
        return AjaxResult.success(favoritesService.getUserImageCol(userId));
    }

    /**
    * @Author zsc
    * @Description 根据ids获取所有图片点赞数量
    * @Date 2024/10/21 10:24
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param ids
    */
    @PostMapping("/getLikeCounts/{ids}")
    public AjaxResult getLikeCounts(@PathVariable Long[] ids) {
        return AjaxResult.success(favoritesService.getLikeCounts(ids));
    }

    /**
    * @Author zsc
    * @Description 根据ids获取所有图片收藏数量
    * @Date 2024/10/21 14:38
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param ids
    */
    @PostMapping("/getColCounts/{ids}")
    public AjaxResult getColCounts(@PathVariable Long[] ids) {
        return AjaxResult.success(favoritesService.getColCounts(ids));
    }

    /**
    * @Author zsc
    * @Description 根据id查询点赞列表
    * @Date 2024/10/23 16:40
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param id
    */
    @GetMapping("/selectLikeImgById")
    public AjaxResult selectLikeImgById(@RequestParam("id") BigInteger id){
        return AjaxResult.success(favoritesService.selectLikeImgById(id));
    }

    /**
    * @Author zsc
    * @Description 根据id查询收藏列表
    * @Date 2024/10/24 11:09
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param id
    */
    @GetMapping("/selectColImgById")
    public AjaxResult selectColImgById(@RequestParam("id") BigInteger id){
        return AjaxResult.success(favoritesService.selectColImgById(id));
    }
}
